from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-04-19 14:11:01.952806
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 19, Apr, 2021
Time: 14:11:06
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.6216
Nobs: 266.000 HQIC: -48.3470
Log likelihood: 3188.00 FPE: 6.19090e-22
AIC: -48.8341 Det(Omega_mle): 4.44126e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.437952 0.123353 3.550 0.000
L1.Burgenland 0.081321 0.061183 1.329 0.184
L1.Kärnten -0.222528 0.053746 -4.140 0.000
L1.Niederösterreich 0.078616 0.132934 0.591 0.554
L1.Oberösterreich 0.215892 0.125933 1.714 0.086
L1.Salzburg 0.270429 0.069834 3.872 0.000
L1.Steiermark 0.117996 0.088814 1.329 0.184
L1.Tirol 0.120516 0.061121 1.972 0.049
L1.Vorarlberg -0.033348 0.056373 -0.592 0.554
L1.Wien -0.056471 0.114439 -0.493 0.622
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.483001 0.143672 3.362 0.001
L1.Burgenland 0.002418 0.071262 0.034 0.973
L1.Kärnten 0.328133 0.062600 5.242 0.000
L1.Niederösterreich 0.070600 0.154831 0.456 0.648
L1.Oberösterreich -0.060749 0.146678 -0.414 0.679
L1.Salzburg 0.222770 0.081337 2.739 0.006
L1.Steiermark 0.103193 0.103444 0.998 0.318
L1.Tirol 0.142556 0.071189 2.003 0.045
L1.Vorarlberg 0.155450 0.065659 2.368 0.018
L1.Wien -0.435449 0.133290 -3.267 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.284377 0.062214 4.571 0.000
L1.Burgenland 0.093907 0.030858 3.043 0.002
L1.Kärnten -0.018608 0.027107 -0.686 0.492
L1.Niederösterreich 0.057809 0.067046 0.862 0.389
L1.Oberösterreich 0.286917 0.063516 4.517 0.000
L1.Salzburg 0.025100 0.035221 0.713 0.476
L1.Steiermark -0.001302 0.044794 -0.029 0.977
L1.Tirol 0.072182 0.030827 2.342 0.019
L1.Vorarlberg 0.084177 0.028432 2.961 0.003
L1.Wien 0.119226 0.057718 2.066 0.039
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.218359 0.060152 3.630 0.000
L1.Burgenland 0.022184 0.029836 0.744 0.457
L1.Kärnten 0.008123 0.026209 0.310 0.757
L1.Niederösterreich 0.048685 0.064824 0.751 0.453
L1.Oberösterreich 0.401369 0.061410 6.536 0.000
L1.Salzburg 0.083042 0.034054 2.439 0.015
L1.Steiermark 0.127752 0.043310 2.950 0.003
L1.Tirol 0.050684 0.029805 1.701 0.089
L1.Vorarlberg 0.083996 0.027490 3.056 0.002
L1.Wien -0.044036 0.055805 -0.789 0.430
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.498938 0.117450 4.248 0.000
L1.Burgenland 0.094859 0.058255 1.628 0.103
L1.Kärnten 0.011947 0.051174 0.233 0.815
L1.Niederösterreich 0.005386 0.126572 0.043 0.966
L1.Oberösterreich 0.130134 0.119907 1.085 0.278
L1.Salzburg 0.059816 0.066492 0.900 0.368
L1.Steiermark 0.062091 0.084564 0.734 0.463
L1.Tirol 0.213178 0.058196 3.663 0.000
L1.Vorarlberg 0.031324 0.053675 0.584 0.560
L1.Wien -0.100263 0.108963 -0.920 0.357
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.193927 0.093347 2.077 0.038
L1.Burgenland -0.010862 0.046300 -0.235 0.815
L1.Kärnten -0.007288 0.040672 -0.179 0.858
L1.Niederösterreich 0.001134 0.100597 0.011 0.991
L1.Oberösterreich 0.412202 0.095300 4.325 0.000
L1.Salzburg 0.015611 0.052846 0.295 0.768
L1.Steiermark -0.031936 0.067210 -0.475 0.635
L1.Tirol 0.160102 0.046253 3.461 0.001
L1.Vorarlberg 0.055213 0.042660 1.294 0.196
L1.Wien 0.216955 0.086602 2.505 0.012
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.241936 0.113020 2.141 0.032
L1.Burgenland 0.017938 0.056058 0.320 0.749
L1.Kärnten -0.071108 0.049244 -1.444 0.149
L1.Niederösterreich -0.080984 0.121798 -0.665 0.506
L1.Oberösterreich 0.025416 0.115384 0.220 0.826
L1.Salzburg 0.083128 0.063984 1.299 0.194
L1.Steiermark 0.332215 0.081374 4.083 0.000
L1.Tirol 0.463300 0.056001 8.273 0.000
L1.Vorarlberg 0.148146 0.051651 2.868 0.004
L1.Wien -0.155623 0.104853 -1.484 0.138
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.186169 0.134949 1.380 0.168
L1.Burgenland 0.039585 0.066935 0.591 0.554
L1.Kärnten -0.074616 0.058799 -1.269 0.204
L1.Niederösterreich 0.130387 0.145430 0.897 0.370
L1.Oberösterreich 0.018238 0.137772 0.132 0.895
L1.Salzburg 0.201537 0.076398 2.638 0.008
L1.Steiermark 0.115631 0.097163 1.190 0.234
L1.Tirol 0.059021 0.066866 0.883 0.377
L1.Vorarlberg 0.101995 0.061672 1.654 0.098
L1.Wien 0.228682 0.125197 1.827 0.068
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.557406 0.073378 7.596 0.000
L1.Burgenland -0.022733 0.036396 -0.625 0.532
L1.Kärnten -0.021913 0.031972 -0.685 0.493
L1.Niederösterreich 0.061385 0.079078 0.776 0.438
L1.Oberösterreich 0.308002 0.074913 4.111 0.000
L1.Salzburg 0.022514 0.041542 0.542 0.588
L1.Steiermark -0.038034 0.052833 -0.720 0.472
L1.Tirol 0.084612 0.036359 2.327 0.020
L1.Vorarlberg 0.110517 0.033534 3.296 0.001
L1.Wien -0.055736 0.068076 -0.819 0.413
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.151213 0.088671 0.165565 0.222239 0.079069 0.084718 0.009398 0.151970
Kärnten 0.151213 1.000000 0.045174 0.205883 0.179495 -0.060193 0.166626 0.026008 0.300162
Niederösterreich 0.088671 0.045174 1.000000 0.236565 0.080972 0.331195 0.144061 0.024951 0.289667
Oberösterreich 0.165565 0.205883 0.236565 1.000000 0.302162 0.263556 0.090801 0.060873 0.130385
Salzburg 0.222239 0.179495 0.080972 0.302162 1.000000 0.155743 0.053491 0.089732 0.011915
Steiermark 0.079069 -0.060193 0.331195 0.263556 0.155743 1.000000 0.102915 0.096519 -0.102026
Tirol 0.084718 0.166626 0.144061 0.090801 0.053491 0.102915 1.000000 0.159512 0.144852
Vorarlberg 0.009398 0.026008 0.024951 0.060873 0.089732 0.096519 0.159512 1.000000 -0.006885
Wien 0.151970 0.300162 0.289667 0.130385 0.011915 -0.102026 0.144852 -0.006885 1.000000